package com.github.live.util;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Html;
import android.widget.Button;

import com.github.livebase.util.html.HTMLException;
import com.github.livebase.util.html.HTMLUtil;


/**
 * @ClassName LiveDialog
 * @description:
 * @author: biao532
 * @create: 2024-01-26 19:34
 * @Version 1.0
 **/
public class LiveDialog extends AlertDialog {

    public LiveDialog(Context context) {
        super(context);
    }

    public LiveDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public LiveDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public void setPositiveButton(CharSequence charSequence, OnClickListener listener) {
        setButton(DialogInterface.BUTTON_POSITIVE, charSequence, listener);
    }

    public void setNeutralButton(CharSequence charSequence, OnClickListener listener) {
        setButton(DialogInterface.BUTTON_NEUTRAL, charSequence, listener);
    }

    public void setNegativeButton(CharSequence charSequence, OnClickListener listener) {
        setButton(DialogInterface.BUTTON_NEGATIVE, charSequence, listener);
    }

    public void removeButton(int whichButton) {
        setButton(whichButton, "", (OnClickListener)null);
    }

    public void setHTMLTitle(String title) {
        super.setTitle(Html.fromHtml(title));
    }

    public void setHTMLMessage(String message) {
        try {
            super.setMessage(HTMLUtil.fromHtml(message));
        } catch (HTMLException e) {
            super.setMessage(message);
            LogFactory.warn(LiveDialog.class, e, "message is [{}]", message);
        }
    }

    public void showAndFocusButton(int switchButton) {
        super.show();
        Button b = getButton(switchButton);
        if (b != null) {
            b.requestFocus();
        }
    }
}
